<?php
/**
 * Frontend class of component WFilesystem
 * @package WFilesystem
 */
require_once 'WKernel/App.php';
require_once 'WKernel/Component.php';
require_once 'WFilesystem/Fs.php';
require_once 'WFilesystem/IRequest/file.php';

class WFs_Component extends WK_Component {
	const NAME = 'WFilesystem';
	private static $_INSTANCE;
	
	private function __construct($config){
		WFs::setRoot(@$config['files_root'] 
						? rtrim($config['files_root'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR 
						: WK_App::getAppRoot());
	}
	
	public static function getInstance($config){
		if(!self::$_INSTANCE)
			self::$_INSTANCE = new self ($config);
		return self::$_INSTANCE;
	}
	
	public function getCommand($name, $params = array()){
		$command_class = 'WFs_Cmd_' . $name;
		$command_file  = self::NAME . '/Commands/' . $name . '.php';
		return $this->getCmdInstance($name, $command_class, $command_file, $params);
	}
}
WK_App::registerComponent(WFs_Component::NAME, 'WFs_Component');